package org.meow.result;

import lombok.Data;
import org.meow.constant.ResCode;

/**
 * &#064;Date: 24/04/22-17:58
 * &#064;Description: 接口返回值
 */
@Data
public class Result<T> {
  private Integer code;
  private String  msg;
  private T  data;

  public static <T> Result<T> success() {
    Result<T> result = new Result<>();
    result.code = ResCode.SUCCESS;
    return result;
  }

  public static <T> Result<T> success(T object) {
    Result<T> result = new Result<>();
    result.data = object;
    result.code = ResCode.SUCCESS;
    return result;
  }

  public static <T> Result<T> error(String msg) {
    Result<T> result = new Result<>();
    result.msg = msg;
    result.code = ResCode.ERROR;
    return result;
  }

  public static <T> Result<T> error(Integer code, String msg) {
    Result<T> result = new Result<>();
    result.code = code;
    result.msg = msg;
    return result;
  }
}
